package com.yichuang.security.common;

/**
  * <p> 服务器状态码信息枚举 </p>
  *
  * @site https://miliqkdoc.motopa.cn/
  * @author tuonioooo
  * @date 2022/12/12 12:12
  */
public enum ServerStatusEnum {

    ERROR_REQUEST(400000, "错误的请求"),

    UNAUTHORIZED(400010, "认证失败"),

    INVALID_TOKEN(400011, "Token已过期"),

    CLIENT_NO_ACCESS_RIGHT(400012, "用户没有权限（令牌、用户名、密码错误）。"),

    ACCOUNT_LOGGED(400013, "The account is logged in on another host. Please login again.");

    private final Integer code;

    private final String desc;

    public Integer getCode()
    {
        return code;
    }

    public String getDesc()
    {
        return desc;
    }

    ServerStatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ServerStatusEnum get(Integer code) {
        for (ServerStatusEnum type : values()) {
            if (type.code.intValue() == code.intValue()) {
                return type;
            }
        }
        return null;
    }

    /**
     * 根据code获取desc
     * @param code
     * @return
     */
    public static String getDesc(Integer code) {
        for (ServerStatusEnum type : ServerStatusEnum.values()) {
            if (type.code.intValue() == code.intValue()) {
                return type.getDesc();
            }
        }
        return "";
    }

}
